package com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Adapter;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tnot.R;
import com.example.tnot.Teacher.CoursePart.ItemBean.rv_ClassListItem;

import org.w3c.dom.Text;

import java.util.List;

public class rvClassListAdapter extends RecyclerView.Adapter<rvClassListAdapter.ViewHolder>{
    List<rv_ClassListItem> ClassList;
    TextView tv_message_success;
    LinearLayout ll_QR_title;
    public rvClassListAdapter(List<rv_ClassListItem> ClassList) {
        this.ClassList = ClassList;
    }

    @NonNull
    @Override
    public rvClassListAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_rv_class_list, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull rvClassListAdapter.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        holder.tv_ClassName.setText(ClassList.get(position).getTv_ClassName());
        holder.tv_number.setText(ClassList.get(position).getTv_number());
//        holder.iv_QR.setImageResource(ClassList.get(position).getIv_QR());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("className",ClassList.get(position).getTv_ClassName());
                bundle.putString("jumpType","教学");
                NavController navController = Navigation.findNavController(v);
                navController.navigate(R.id.action_courseDetailFragment_to_classDetailFragment,bundle);
            }
        });


        holder.iv_QR.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NavController navController = Navigation.findNavController(v);
//                tv_message_success = v.findViewById(R.id.tv_message_success);
//                tv_message_success.setVisibility(View.GONE);
//                ll_QR_title = v.findViewById(R.id.ll_QR_title);
//                ll_QR_title.setVisibility(View.GONE);

                navController.navigate(R.id.createQRcodeFragment);
            }
        });
    }

    @Override
    public int getItemCount() {
        return ClassList==null? 0: ClassList.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        TextView tv_ClassName,tv_number;
        ImageView iv_QR;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_ClassName = itemView.findViewById(R.id.tv_ClassName);
            tv_number = itemView.findViewById(R.id.tv_number);
            iv_QR = itemView.findViewById(R.id.iv_QR);
        }
    }
}
